<script setup>
  import {ref} from "vue";

  const a=ref('')
  const b=ref('')
  const res=ref('')
  const calc=(o)=>{
    res.value=eval(a.value+o+b.value)
  }
</script>

<template>
  <h1>计算器</h1>
  <input type="text" v-model="a">
  <input type="text" v-model="b">
  <button @click="calc('+')">加</button>
  <button @click="calc('-')">减</button>
  <button @click="calc('*')">乘</button>
  <button @click="calc('/')">除</button>
  <h4>结果是:{{res}}</h4>
</template>

<style scoped>

</style>